/**
 * only for test
 */


/// <reference path="./cesium.d.ts" />

//import * as Cesium from 'Cesium';


export class CesiumDemo {
    private _viewer: Cesium.Viewer;
    private _tm: Cesium.Cesium3DTileset;
    constructor() { }

    start() {

        //let ces= document.getElementById("cesium");
        //ces.innerHTML="这只是测试-实时更新么？";

        let viewer = this._viewer = new Cesium.Viewer("cesium", {
            animation: false,
            baseLayerPicker: false,
            fullscreenButton: false,
            geocoder: false,
            homeButton: false,
            infoBox: false,
            sceneModePicker: false,
            selectionIndicator: false,
            timeline: false,
            navigationHelpButton: false,
            navigationInstructionsInitiallyVisible: false,
            imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
                url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
            }),
            // terrainProvider: new Cesium.CesiumTerrainProvider({
            //     "url": 'https://assets.agi.com/stk-terrain/world'
            // })

        });

        let tilesetModel4 = this._tm = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
            url: 'http://freedoonline.com:9999/BIM/osgdata69_out/'  // 
        }));

    }

    setView(lon: number, lat: number, height: number, heading: number, pitch: number, roll: number) {
        this._viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
            orientation: {
                heading: Cesium.Math.toRadians(heading),
                pitch: Cesium.Math.toRadians(pitch),
                roll: Cesium.Math.toRadians(roll)
            }
        });
    }



    private setSelectedStyle(id: string, tileset: Cesium.Cesium3DTileset) {
        tileset.style = new Cesium.Cesium3DTileStyle({
            color: {
                conditions: [
                    ["${component} === \'" + id + "\'", "color('red')"],
                    ["true", "color('white')"]
                ]
            }
        });
    }

    initEvent() {
        var myScreenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(this._viewer.canvas);
        myScreenSpaceEventHandler.setInputAction((movement) => {
            var pickedObject = this._viewer.scene.pick(movement.position);
            if (pickedObject) {
                var _batchId = pickedObject._batchId;
                var f = pickedObject._batchTable.batchTableJson.component[_batchId];
                this.setSelectedStyle(f, this._tm)
            };
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    }

}

